﻿//********************************************************************
// FileName: Labels.js
// Description: Labels.js
// Author: harden
// CreateTime: 2019-09-11 harden
// EditHistory: 2019-09-11 harden Create
// Function:页面加标处的公共代码
//********************************************************************
function Labels() {
    this.ConstructLabel = function (selecteddivId, fuzzysearchdivId, selectButtonId, initlist, indiv) {
        //多选下拉框所在的div
        var selecteddiv = document.getElementById(selecteddivId);
        var checkBoxName = "mycheckbox" + selectButtonId;
        //动态创建所有的checkbox元素
        for (var i = 0; i < initlist.length; i++) {
            var tmpdiv = document.createElement("div");
            var tmpinput = document.createElement("input");
            tmpinput.setAttribute("name", checkBoxName);
            tmpinput.setAttribute("type", "checkbox");
            tmpinput.setAttribute("onclick", "mycheck(this,this.name)");
           // tmpinput.setAttribute("onclick", mycheck(this,selectButtonId));
            tmpinput.setAttribute("value", initlist[i]);

            var tmptext = document.createTextNode(initlist[i]);
            tmpdiv.appendChild(tmpinput);
            tmpdiv.appendChild(tmptext);
            if(tmpdiv != null)
                selecteddiv.appendChild(tmpdiv);
        }
    }
    this.mycheck = function (obj, selectButtonId, selectedlist, selectednamelist) {
        if (obj.checked) {
            selectedlist.push(obj.value);
            selectednamelist.push(obj.nextSibling.nodeValue);
        } else {
            for (var i = 0; i < selectedlist.length; i++) {
                if (selectedlist[i] == obj.value) {
                    selectedlist.splice(i, 1);
                    selectednamelist.splice(i, 1);
                }
            }
        }
        document.getElementById(selectButtonId).value = selectednamelist;
    }
}